<?php

class SubfolderAccessManager_Validate_EmailIdenticalToCurrent extends Zend_Validate_Abstract
{
	const EMAIL_NOT_IDENTICAL = 'emailNotIdentical';
	
	protected $_messageTemplates = array(
			self::EMAIL_NOT_IDENTICAL => 'Incorrect current email address'
	);
	
	public function isValid($value)
	{
		$auth = Zend_Auth::getInstance();
		if ($auth->hasIdentity()) {
			$userId = $auth->getIdentity()->id;
			$userDbTable = new Application_Model_DbTable_Users();
			$userData = $userDbTable->getUser($userId);
			$currentEmail = $userData['email_address'];
			
			if ($currentEmail != $value) {
				$this->_error(self::EMAIL_NOT_IDENTICAL);
				return false;
			}
		}
		
		return true;
	}
}